package com.softeem.train.action;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class FilterTest implements javax.servlet.Filter {
	public FilterTest() {
		System.out.println("FilterTest过滤器初始化！！！");
	}

	@Override
	public void destroy() {
		System.out.println("执行了FilterTest---->destroy()方法");
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		System.out.println("请求的URL----->"+req.getRequestURI());
		System.out.println("服务器的真实路径地址："+req.getRealPath(""));
		System.out.println("对请求进行了拦截！！！");
		chain.doFilter(request, response);
		System.out.println("调用结束！！！");
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		String mark = filterConfig.getInitParameter("mark");
		if ("true".equals(mark)) {
			System.out.println("执行了FilterTest---->init()方法");
		} else {
			System.out.println("没有执行了FilterTest---->init()方法");
		}
	}

}
